/** @file CommandList.h
    @class CommandList
    @brief Singleton class controlling the command buffer
*/
#ifndef _CommandList_h_
#define _CommandList_h_

#include <list>
#include "GameState.h"
#include "Command.h"
#include "Model.h"
#include "DataPacker.h"
#include "NetworkController.h"

using namespace std;

class CommandList {
public:
	/**
	* @brief Returns the instance of the CommandList
	*/
	static CommandList* getInstance();

	/**
	* @brief Returns the address to the list of commands
	*/
	list<Command*>* getList();
	
	/**
	* @brief Adds a command list to the CommandList's command list
	*/
	void addList(list<Command*> &list);
	
	/**
	* @brief Adds a command to the command list
	*/
	void add(Command* obj);
	
	/**
	* @brief Adds a command to the network command list
	*/
	void addNetwork(Command* obj);
	
	/**
	* @brief Executes each command in the command list and network command list; Saves the commands to the replay file; Sends the command list to the network controller
	*/
	void execute(Model* m);
	
	/**
	* @brief Sets the network controller
	*/
	void setNetworkController(NetworkController* nc);
	
	/**
	* @brief Returns the network controller
	*/
	NetworkController* getNetworkController();
	
	/**
	* @brief Sets the game state
	*/
	void setGameState(GameState* gs);
	
	/**
	* @brief Returns the game state
	*/
	GameState* getGameState();
	//void setSync(bool val);
	
	
private:
	/**
	* @brief The CommandList's instance
	*/
	static CommandList* instance;
	
	/**
	* @brief The command list
	*/
	list<Command*> commands;
	
	/**
	* @brief The network command list
	*/
	list<Command*> networkList;
	
	/**
	* @brief The data packer which it saves commands to
	*/
	DataPacker* packer;
	
	/**
	* @brief The network controller
	*/
	NetworkController* network;
	
	/**
	* @brief The game state
	*/
	GameState* state;

	bool sync;

	/**
	* @brief The constructor
	*/
	CommandList();
	
	/**
	* @brief The decinstructor
	*/
	virtual ~CommandList();
	
	/**
	* @brief Executs each command in the netowrk command list and saves them to the replay file
	*/
	void executeNetwork(Model* m);
};

#endif